package com.findtech.threePomelos.fragment;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.findtech.threePomelos.R;
import com.findtech.threePomelos.entity.TravelInfoEntity;
import com.findtech.threePomelos.utils.RequestUtils;
import com.findtech.threePomelos.utils.Tools;
import com.findtech.threePomelos.view.arcview.MileageArcView;
import com.findtech.threePomelos.view.arcview.UserInfoModel;

public class MileageFragment extends Fragment {

    private TextView todayMileage, totalMileage;
    private TravelInfoEntity travelInfoEntity = TravelInfoEntity.getInstance();
    private View view;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_mileageinfo, container, false);
        ((MileageArcView) view.findViewById(R.id.panel)).setDataModel(getData());
        todayMileage = (TextView) view.findViewById(R.id.today_mileage_fragment);
        totalMileage = (TextView) view.findViewById(R.id.total_mileage_fragment);
        todayMileage.setText(getResources().getString(R.string.xliff_today_mileage_fragment_num, travelInfoEntity.getTodayMileage()));
        totalMileage.setText(getResources().getString(R.string.xliff_total_mileage_fragment_num, travelInfoEntity.getTotalMileage()));
        return view;
    }

    public void setAsShareFragement(boolean isShare) {
        if (isShare) {
            view.setBackgroundColor(getResources().getColor(R.color.share_background_color));
        } else {
            view.setBackgroundColor(getResources().getColor(R.color.light_red_color));
        }
    }

    private UserInfoModel getData() {
        UserInfoModel model = new UserInfoModel();
        TravelInfoEntity travelInfoEntity = TravelInfoEntity.getInstance();
        String mileageNum = RequestUtils.getSharepreference(getContext()).getString(RequestUtils.MILEAGE, travelInfoEntity.getAverageSpeed());
        try {
            mileageNum = Tools.extractStringFirstPoint(mileageNum);
            model.setUserTotal(Double.parseDouble(mileageNum));
        } catch (Exception e) {
            e.printStackTrace();
        }
        model.setAssess("平均时速");
        model.setTotalMin(00.0);
        model.setTotalMax(20);
        return model;
    }
}
